package com.trkj.service.hjj;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.trkj.dao.hjj.CreditCardDataDAO;
import com.trkj.dao.wdm.DefinitionDeptDao;
import com.trkj.dao.wdm.StaffInformationDAO;
import com.trkj.mybatisdao.staffDeptDAO;
import com.trkj.pojo.DefinitionDept;
import com.trkj.pojo.Slotcarddate;
import com.trkj.pojo.StaffInformation;
import com.trkj.service.ServiceException;
import com.trkj.vo.SloscarddateVo;
import com.trkj.vo.hjj.OperationVo;

@Service
@Transactional(rollbackFor=Exception.class)
public class CreditCardDataService {
	@Autowired
	private CreditCardDataDAO creditCardDataDAO;//刷卡dao
	@Autowired
	private DefinitionDeptDao definitionDeptDAO;
	@Autowired
	private StaffInformationDAO staffDAO;
	@Autowired
	private staffDeptDAO staffdeptDAO;//刷卡数据
	/**
	 *时间名字  查询数据列表
	 * @param stainDate
	 * @param stainEndDate
	 * @param stainName
	 * @return
	 */
	public JSONArray findTimeByNameandTime(String stainDate,String stainEndDate,String stainName){
		return staffdeptDAO.findTimeByNameandTime(new OperationVo(stainDate, stainEndDate, "%"+stainName+"%"));
	}
	/**
	 * 打卡
	 * @return
	 */
	public boolean playCard(Long stainId)throws ServiceException{
		try {
			JSONArray json = staffdeptDAO.findTimecardDataList();
			
			
			StaffInformation staff= staffDAO.findOne(stainId);
			Slotcarddate slo = new Slotcarddate();
			slo.setStaffInformation(staff);
			slo.setSlotcardDate(new Timestamp(new Date().getTime()));
			slo.setSlotcardEffect(new BigDecimal(0));
			creditCardDataDAO.save(slo);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 分页查询刷卡数据
	 * @param page
	 * @param rows
	 * @return
	 */
	public JSONArray findAllSol()throws ServiceException{
		return staffdeptDAO.findTimecardDataList();
	}
	/**
	 * 按照部门查找刷卡数据
	 */
	public JSONArray findTimecardDataListBydName(String dName){
		return staffdeptDAO.findTimecardDataListBydName(dName);
	}
	
}
